package com.hkx.smipleemps.servlet;

import com.hkx.smipleemps.common.domain.Employee;
import com.hkx.smipleemps.common.utils.DateUtil;
import com.hkx.smipleemps.common.utils.PageInfo;
import com.hkx.smipleemps.service.EmployeeService;
import com.hkx.smipleemps.service.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@WebServlet("/listEmployee.do")
public class ListEmployeeServlet extends HttpServlet {
    EmployeeService employeeService = new EmployeeServiceImpl();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //
        String pageNoStr = request.getParameter("pageNo");
        int pageNo = 1;
        if (pageNoStr != null) {
            pageNo = Integer.parseInt(pageNoStr.trim());//"3" ---3
        }
        String pageSizeStr = request.getParameter("pageSize");
        int pageSize = 5;
        if (pageSizeStr != null) {
            pageSize = Integer.parseInt(pageSizeStr.trim());//"3" ---3
        }

        PageInfo<Employee> pageInfo = employeeService.findEmployees(pageNo, pageSize);

       /* request.setAttribute("emps",employees);
        request.setAttribute("pageNo",pageNo);
        request.setAttribute("pageSize",pageSize);*/
        request.setAttribute("pageInfo", pageInfo);
        request.getRequestDispatcher("/emp-list.jsp").forward(request, response);
    }
}
